#ifndef __FIELD_GENERATOR_H__
#define __FIELD_GENERATOR_H__

//Given a game state object this class will generate potential fields for the map
//These fields will be later used for making navigation decisions as well as
//strategic planning.

//Each ant will move to the next highest potential square every turn or stay
//at the same spot if the potential is highest at the location of the ant.

//Food/enemies will generate strong potential fields to attract our ants

#include <vector>
#include <map>
class Location;
class State;

const double FRIENDLYANT_BASEPOTENTIAL = 20000;
const double ENEMYANT_BASEPOTENTIAL = 5000;
const double FOOD_BASEPOTENTIAL = 500;

class PotentialField {
private:
    const State& m_state;
    std::vector<std::vector<double> > *field;
    std::map<Location,double > potentialCache;
    std::map<Location,double > quadCache;
public:
    //Builds the potential field by looking at 
    //each food/ant and enemy ant location and 
    //does an exponential fall off over a certain radius
    PotentialField(const State& state);
    
    void clearCaches();
    void initField();
    void visited(const Location& loc);
    //Query the field to figure out 
    //Returns the direction to move in for next highest potential square adjacent to this one
    //false if current square is already highest
    bool higher(const Location& loc,int& direction);

    //Returns the lowest potential square adjacent to this one
    //false if current square is already lowest
    bool lower(const Location& loc,int& direction);

private: 
    double getPotential(const Location& loc);
    double getQuadrantPotential(const Location& loc);
    double getFriendlyAntPotential(const Location& sourceLoc,const Location& targetLoc);
    double getEnemyAntPotential(const Location& sourceLoc,const Location& targetLoc);
    double getFoodPotential(const Location& sourceLoc,const Location& targetLoc);
};
#endif
